package com.easytouch.vmhdl.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Button;

/**
 * Created by Administrator on 2018/1/17.
 */

@SuppressLint("AppCompatCustomView")
public class RipperButton extends Button {
    private RipperDrawable mRipperDrawable;

    public RipperButton(Context context) {
        this(context,null);
    }

    public RipperButton(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public RipperButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mRipperDrawable=new RipperDrawable();
        //设置刷新接口，View中已经实现
        mRipperDrawable.setCallback(this);

    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        //设置Drawable绘制和刷新区域
        mRipperDrawable.setBounds(0,0,getWidth(),getHeight());
    }


    @Override
    protected boolean verifyDrawable(@NonNull Drawable who) {
        //验证Drawable是否OK
        return who == mRipperDrawable || super.verifyDrawable(who);
    }

    @Override
    protected void onDraw(Canvas canvas) {

        mRipperDrawable.draw(canvas);

        super.onDraw(canvas);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        mRipperDrawable.onTouch(event);
         super.onTouchEvent(event);
         return true;

    }
}
